<?php
hc_core_ClassLoader::load('halo_IController');
class examples_single_controller_Form implements halo_IController {
    protected $sampleDao;
    protected $formSuccessView;
    protected $formFailureView;
    protected $formView;
    public function __construct($sampleDao, $formView, $formSuccessView, $formFailureView) {
        $this->sampleDao = $sampleDao;
        $this->formView = $formView;
        $this->formSuccessView = $formSuccessView;
        $this->formFailureView = $formFailureView;
    }
    public function handleRequest(halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) {
        if ( $httpRequest->isPostMethod() ) {
            return $this->doPost($httpRequest, $httpResponse);
        } else {
            return $this->doShowForm($httpRequest, $httpResponse);
        }
    }
    function doPost(halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) {
        if ( $httpRequest->postParamExists('sampleInput') and $this->sampleDao->contains($httpRequest->getPostParam('sampleInput')) ) {
            return new halo_ModelAndView($this->formSuccessView, array(
                'queriedItem' => $httpRequest->getPostParam('sampleInput'),
                'itemId' => $this->sampleDao->idFor($httpRequest->getPostParam('sampleInput'))
            ));
        }
        else {
            return new halo_ModelAndView($this->formFailureView, array('failure' => 1));
        }
    }
    function doShowForm(halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) {
        $model = array();
        if ( $httpRequest->queryParamExists('failure') ) {
            $model['failure'] = true;
        } else {
            $model['failure'] = false;
        }
        return new halo_ModelAndView($this->formView, $model);
    }
}
?>
